# -*- coding: utf-8 -*-
"""
@Time ： 2021/1/7 15:22
@Auth ： Mr. JJ_Cloud
@Company ：testingedu.com.cn
@Function ：文件下载器
"""

import os
import requests

class FileDownloader():  #类名
    def __init__(self,url):  #类的初始化
        self.url= url

    def download_file(self):
        s = requests.get(self.url)
        file_name = self.url.split('/')[-1]
        with open(file_name,'wb') as hf:
            hf.write(s.content)
        file_path = os.path.abspath(file_name)
        print("file downloaded to %s " % file_path)
        return file_path

if __name__ == '__main__':
    fd_obj = FileDownloader('http://www.zipython.com/images/angel.mp3')# FileDownloader类初始化，成fd_obj对象
    fd_obj.download_file() # 一般对象才能调用方法（函数）